package com.集合.Collection___;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

@SuppressWarnings("all")
public class CollectionExercise01 {
    /**
     * 用Iterator迭代器 和 增强for 来遍历集合
     */
    public static void main(String[] args) {
        Collection list = new ArrayList();
        list.add(new Dog("旺财",4));
        list.add(new Dog("大壮",6));
        list.add(new Dog("小黄",1));

        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        System.out.println("=============================");
        for (Object o : list) {
            System.out.println(o);
        }

    }
}

class Dog{
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                "岁}";
    }
}